﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using Daycare.Models;

namespace Daycare.DAL
{
    public class ImageRepository
    {
        public Models.Image AddImage(String fileName)
        {
            try
            {
                using (SqlConnection con = new SqlConnection(Configuration.ConnectionString))
                {
                    using (SqlCommand comm = new SqlCommand("daycare.AddImage", con))
                    {
                        comm.CommandType = CommandType.StoredProcedure;
                        comm.Parameters.AddWithValue("@FileName", fileName);

                        Models.Image img = new Models.Image();
                        img.fileName = fileName;

                        con.Open();
                        int imageId = 1;
                        Int32.TryParse(comm.ExecuteScalar().ToString(), out imageId);
                        img.imageId = imageId;
                        return img;
                    }
                }
            }
            catch(SqlException)
            {
                return null;
            }
        }
    }
}